/*
 * @(#)Main.java   1.0   May 7, 2007
 *
 * Copyright 2000-2007 ETH Zurich. All Rights Reserved.
 *
 * This software is the proprietary information of ETH Zurich.
 * Use is subject to license terms.
 *
 * @(#) $Id: Main.java 430 2007-05-20 22:24:39Z D\aldespin $
 */
package ch.ethz.globis.javaom.helloworld;

import ch.ethz.globis.javaom.core.AttributeValue;
import ch.ethz.globis.javaom.core.Bulk;
import ch.ethz.globis.javaom.core.Object;
import ch.ethz.globis.javaom.system.Metadata;
import ch.ethz.globis.javaom.utils.TypeUtils;

/**
 * @author aldespin
 * @version 1.0
 */
public class Main {

   public static void main(final String[] args) {
      System.out.println("> hello");

      // create an attribute object
      final Object nameAttribute = new Object();
      // dress the object with the object and attribute types
      nameAttribute.dress(Metadata.METADATA.getTypeObject(Metadata.OBJECT));
      nameAttribute.dress(Metadata.METADATA.getTypeObject(Metadata.ATTRIBUTE));
      // set the name attribute to be "nickname"
      nameAttribute.setAttributeValue(Metadata.METADATA.getAttributeObject(Metadata.ATTRIBUTE,
            Metadata.NAME), new AttributeValue<String>(Metadata.METADATA
            .getTypeObject(Metadata.STRING), "nickname"));
      // set the type attribute to be string
      nameAttribute.setAttributeValue(Metadata.METADATA.getAttributeObject(Metadata.ATTRIBUTE,
            Metadata.TYPE), Metadata.METADATA.getTypeObject(Metadata.STRING));

      // create person type object
      final Object personType = TypeUtils.create("person");
      // declare name attribute for person type
      TypeUtils.declareTypeAttribute(personType, nameAttribute);

      // create person object
      final Object person = new Object();
      // dress with object and person types
      person.dress(Metadata.METADATA.getTypeObject(Metadata.OBJECT));
      person.dress(personType);

      // set attribute value
      person.setAttributeValue(nameAttribute, new AttributeValue<String>(Metadata.METADATA
            .getTypeObject(Metadata.STRING), "damian"));

      // get attribute value
      final Bulk names = person.getAttributeValue(nameAttribute);
      for (Object current : names) {
         System.out.println("> person.name: " + ((AttributeValue) current).getValue());
      }

      System.out.println("> good bye");
   }
}
